package com.Vma.aop;

import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;

import com.Vma.util.CommonUtil;
import com.Vma.util.JsonUtil;

import net.sf.json.JSONObject;
@Aspect
public class Aoptest {
	/**
	 * 
	 * @param joinpoint
	 * @throws Exception
	 * @remarks 本方法只适用于使用HttpServletRequest与HttpServletResponse作为参数的接口
	 * @author 金志敏_alex
	 */
	public synchronized  void begin(JoinPoint joinpoint) throws Exception{
		Class[] parameterTypes = new Class[joinpoint.getArgs().length];
		Object[] args = joinpoint.getArgs();
		HttpServletRequest request = (HttpServletRequest)args[0];
		HttpServletResponse response = (HttpServletResponse)args[1];
		JSONObject jsonobject = JsonUtil.GetSfJson(request, response);
		Iterator<String> it =jsonobject.keys();
		JSONObject notNullJson = new JSONObject();
		while(it.hasNext()) {
			String key=it.next();
			Object value = null;
			value=jsonobject.get(key);
			if(CommonUtil.isNotEmpty(value)) {
				notNullJson.put(key, value);
			}
		}
		request.setAttribute("jsonobject", notNullJson);
	}
}
